const express = require('express');
const router = express.Router();
const db = require('../../utils/db');

// 获取折扣商品数据
router.get('/getdiscountfood',function(req,res){
    let mysql='SELECT menu_id,pack_discount,menu_price FROM package_list JOIN menu_file ON package_list.pack_num=menu_file.menu_id';
    db(mysql,null,(err,data)=>{
        if (err) {
            return res.json({
              code: 500,
              msg: '查询折扣商品失败'
            })
          }
          res.json({
            code: 200,
            msg: '查询折扣商品成功',
            data: data
          })
    })
})

// 获取菜品月销售量
router.get('/getmonthsale',function(req,res){
    let mysql=`SELECT menu_id,dish_amount,order_time FROM dish_flowing 
               JOIN menu_file ON dish_flowing.dish_name=menu_file.menu_id
               JOIN order_information ON dish_flowing.dish_time=order_information.order_id 
               WHERE menu_id=${req.query.id} AND order_time LIKE '${req.query.time}%'`;
    db(mysql,null,(err,data)=>{
        if (err) {
            return res.json({
              code: 500,
              msg: '查询商品月销售量失败'
            })
          }
          res.json({
            code: 200,
            msg: '查询商品月销售量成功',
            data: data
          })
    })
})

module.exports = router